import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex)
import service from "@/service"
const store = new Vuex.Store({
	state: {
		token: uni.getStorageSync('token'),
		hasLogin: false,
		userInfo: {},
		permmenu: {}
	},
	mutations: {
		login(state, res) {
			state.hasLogin = true
			state.token = res.token
			uni.setStorageSync('token', res.token)
		},
		// 存储用户信息
		SET_PERSON(state, res) {
			state.hasLogin = true
			state.userInfo = res
			uni.setStorageSync('userInfo', res)
		},
		//获取权限列
		SET_PERM(state, res) {
			state.permmenu = res.menus
			uni.setStorageSync('permmenu', res.menus)
		}
	},
	actions: {
		getUserInfo({ commit }) {
			service.common.userInfo().then((res) => {
				commit('SET_PERSON', res)
			})
		},
		getUserPerm({ commit }) {
			service.common.permMenu().then((res) => {
				commit('SET_PERM', res)
			})
		}
	}
});

export default store;
